package com.graduation.springbootinit.controller;

import com.graduation.springbootinit.common.BaseResponse;
import com.graduation.springbootinit.common.ResultUtils;
import com.graduation.springbootinit.model.entity.ShopPart.RegionDict;
import com.graduation.springbootinit.service.RegionDictService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/shopPart/region")
public class RegionDictController {

    @Resource
    private RegionDictService regionDictService;

    @GetMapping("/provinces")
    public BaseResponse<List<RegionDict>> listProvinces() {
        return ResultUtils.success(regionDictService.listProvinces());
    }

    @PostMapping("/cities")
    public BaseResponse<List<RegionDict>> listCities(@RequestBody RegionDict region) {
        return ResultUtils.success(regionDictService.listCities(region.getParentCode()));
    }

    @PostMapping("/districts")
    public BaseResponse<List<RegionDict>> listDistricts(@RequestBody RegionDict region) {
        return ResultUtils.success(regionDictService.listDistricts(region.getParentCode()));
    }

    @PostMapping("/get")
    public BaseResponse<RegionDict> getByCode(@RequestBody RegionDict region) {
        return ResultUtils.success(regionDictService.getByCode(region.getCode()));
    }
} 